from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-01-06 14:14:03.723390
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 06, Jan, 2021
Time: 14:14:07
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -44.6739
Nobs: 163.000 HQIC: -45.6886
Log likelihood: 1788.56 FPE: 7.19610e-21
AIC: -46.3821 Det(Omega_mle): 4.21086e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.460132 0.156132 2.947 0.003
L1.Burgenland 0.137391 0.079152 1.736 0.083
L1.Kärnten -0.235638 0.063890 -3.688 0.000
L1.Niederösterreich 0.116710 0.184661 0.632 0.527
L1.Oberösterreich 0.252018 0.158200 1.593 0.111
L1.Salzburg 0.174201 0.081716 2.132 0.033
L1.Steiermark 0.080066 0.113895 0.703 0.482
L1.Tirol 0.146300 0.075899 1.928 0.054
L1.Vorarlberg 0.009116 0.072654 0.125 0.900
L1.Wien -0.123052 0.152882 -0.805 0.421
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.512681 0.201622 2.543 0.011
L1.Burgenland 0.010695 0.102214 0.105 0.917
L1.Kärnten 0.366680 0.082505 4.444 0.000
L1.Niederösterreich 0.136174 0.238463 0.571 0.568
L1.Oberösterreich -0.185431 0.204293 -0.908 0.364
L1.Salzburg 0.186323 0.105525 1.766 0.077
L1.Steiermark 0.249533 0.147079 1.697 0.090
L1.Tirol 0.142820 0.098013 1.457 0.145
L1.Vorarlberg 0.177274 0.093822 1.889 0.059
L1.Wien -0.581268 0.197425 -2.944 0.003
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.294423 0.068470 4.300 0.000
L1.Burgenland 0.102555 0.034711 2.955 0.003
L1.Kärnten -0.027155 0.028018 -0.969 0.332
L1.Niederösterreich 0.064931 0.080981 0.802 0.423
L1.Oberösterreich 0.293376 0.069377 4.229 0.000
L1.Salzburg 0.000712 0.035836 0.020 0.984
L1.Steiermark -0.021838 0.049947 -0.437 0.662
L1.Tirol 0.090080 0.033285 2.706 0.007
L1.Vorarlberg 0.126312 0.031861 3.964 0.000
L1.Wien 0.082867 0.067045 1.236 0.216
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.203213 0.078666 2.583 0.010
L1.Burgenland -0.012655 0.039880 -0.317 0.751
L1.Kärnten 0.022161 0.032190 0.688 0.491
L1.Niederösterreich 0.025701 0.093040 0.276 0.782
L1.Oberösterreich 0.412144 0.079708 5.171 0.000
L1.Salzburg 0.096993 0.041172 2.356 0.018
L1.Steiermark 0.182019 0.057385 3.172 0.002
L1.Tirol 0.033531 0.038241 0.877 0.381
L1.Vorarlberg 0.095702 0.036606 2.614 0.009
L1.Wien -0.060291 0.077028 -0.783 0.434
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.592639 0.164162 3.610 0.000
L1.Burgenland 0.074880 0.083223 0.900 0.368
L1.Kärnten 0.002545 0.067176 0.038 0.970
L1.Niederösterreich -0.035876 0.194158 -0.185 0.853
L1.Oberösterreich 0.153877 0.166337 0.925 0.355
L1.Salzburg 0.051510 0.085919 0.600 0.549
L1.Steiermark 0.110229 0.119753 0.920 0.357
L1.Tirol 0.210200 0.079803 2.634 0.008
L1.Vorarlberg 0.004800 0.076391 0.063 0.950
L1.Wien -0.147088 0.160745 -0.915 0.360
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158994 0.114255 1.392 0.164
L1.Burgenland -0.027952 0.057923 -0.483 0.629
L1.Kärnten -0.012813 0.046754 -0.274 0.784
L1.Niederösterreich 0.177060 0.135132 1.310 0.190
L1.Oberösterreich 0.394859 0.115768 3.411 0.001
L1.Salzburg -0.027834 0.059799 -0.465 0.642
L1.Steiermark -0.047286 0.083347 -0.567 0.570
L1.Tirol 0.189837 0.055542 3.418 0.001
L1.Vorarlberg 0.040383 0.053167 0.760 0.448
L1.Wien 0.162844 0.111877 1.456 0.146
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.236538 0.144642 1.635 0.102
L1.Burgenland 0.061873 0.073327 0.844 0.399
L1.Kärnten -0.049254 0.059188 -0.832 0.405
L1.Niederösterreich -0.025512 0.171071 -0.149 0.881
L1.Oberösterreich -0.102295 0.146558 -0.698 0.485
L1.Salzburg 0.011208 0.075703 0.148 0.882
L1.Steiermark 0.374332 0.105513 3.548 0.000
L1.Tirol 0.517613 0.070313 7.362 0.000
L1.Vorarlberg 0.197437 0.067307 2.933 0.003
L1.Wien -0.219231 0.141631 -1.548 0.122
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.119390 0.169087 0.706 0.480
L1.Burgenland 0.007518 0.085720 0.088 0.930
L1.Kärnten -0.115939 0.069191 -1.676 0.094
L1.Niederösterreich 0.207998 0.199983 1.040 0.298
L1.Oberösterreich 0.019042 0.171327 0.111 0.912
L1.Salzburg 0.227750 0.088497 2.574 0.010
L1.Steiermark 0.142193 0.123345 1.153 0.249
L1.Tirol 0.095216 0.082197 1.158 0.247
L1.Vorarlberg 0.013285 0.078682 0.169 0.866
L1.Wien 0.293889 0.165567 1.775 0.076
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.585882 0.092414 6.340 0.000
L1.Burgenland -0.022150 0.046850 -0.473 0.636
L1.Kärnten -0.000292 0.037816 -0.008 0.994
L1.Niederösterreich -0.011597 0.109300 -0.106 0.916
L1.Oberösterreich 0.282635 0.093639 3.018 0.003
L1.Salzburg 0.011887 0.048368 0.246 0.806
L1.Steiermark -0.000804 0.067414 -0.012 0.990
L1.Tirol 0.077272 0.044925 1.720 0.085
L1.Vorarlberg 0.169387 0.043004 3.939 0.000
L1.Wien -0.087750 0.090491 -0.970 0.332
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.138189 -0.002072 0.202911 0.243088 0.060104 0.101386 -0.081140 0.160908
Kärnten 0.138189 1.000000 -0.008133 0.187084 0.131967 -0.145100 0.172581 0.028466 0.298069
Niederösterreich -0.002072 -0.008133 1.000000 0.257409 0.074410 0.205502 0.110587 0.057373 0.352598
Oberösterreich 0.202911 0.187084 0.257409 1.000000 0.277881 0.291433 0.108164 0.070970 0.109371
Salzburg 0.243088 0.131967 0.074410 0.277881 1.000000 0.144420 0.074684 0.076116 -0.020052
Steiermark 0.060104 -0.145100 0.205502 0.291433 0.144420 1.000000 0.108549 0.090329 -0.129374
Tirol 0.101386 0.172581 0.110587 0.108164 0.074684 0.108549 1.000000 0.154608 0.144975
Vorarlberg -0.081140 0.028466 0.057373 0.070970 0.076116 0.090329 0.154608 1.000000 0.104158
Wien 0.160908 0.298069 0.352598 0.109371 -0.020052 -0.129374 0.144975 0.104158 1.000000